home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / vesa_tsr.zip / C&T / VESA452.ASM < prev    next >
Assembly Source File  |  1990-04-18  |  24KB  |  908 lines

  1.     page 70, 132
  2.  
  3.  
  4.  
  5. ;----------------------------------------------------------------------
  6. ; Module Name    :VESA452.asm
  7. ; Program Name    :VESA452.com
  8. ; Description    :This program traps Video BIOS Fuction calls made from an
  9. ;        Application program. It is a TSR(Terminate & Stay Resident)
  10. ;        program.
  11. ; Date        :February 26, 1990
  12. ; Version    :1.0
  13. ; Programmer    :Rakesh K. Jain
  14. ; Copyright (C) Chips and Technologies, Inc. 1990
  15. ;----------------------------------------------------------------------
  16.  
  17.     include    vesa.inc        ; to include VESA structures & constants
  18.     include    vesa452.inc        ; 452 related stuff
  19.  
  20. ;
  21. ; Code Segment Starts
  22. ;
  23.     code    segment
  24.     assume    cs:code, ds:code, ss:code, es:code
  25.  
  26.     org    100h            ;for making the program .COM type
  27.  
  28. begin    :
  29.     jmp    main            ; jump to the initialization part
  30.  
  31.  
  32. ;------------------------------------------------------------------
  33. ;    This routine stores BIOS Video Function Number into a Buffer
  34. ;    and then calls BIOS fuction.
  35. ;------------------------------------------------------------------
  36. VideoHandler proc    near
  37. ; look for functions to be implemented here
  38.     cmp    ah, VESA_FUNCTIONS
  39.     jnz    VHNotVGACntlFun
  40.  
  41. ; Its a VESA function
  42.     call    VESAFunctions
  43.     iret
  44.  
  45. VHNotVGACntlFun:
  46.     pushf            ;Push Flags to compensate for IRET
  47.     callfar
  48. oldvect    dw    0
  49.     dw    0        ;Old Video Interrupt Vector
  50.     iret
  51. VideoHandler endp
  52.  
  53.  
  54.  
  55. VESAFunctions proc    near
  56.     cmp    al, MAX_FUNCTIONS
  57.     ja    VESAFNotAValidFunction
  58.     cmp    al,5                ; Window Control function
  59.     jnz    @F
  60.     push    cs
  61.     call    near ptr SuperVGASetCPUMemWin    ; This is far call
  62.     ret
  63. @@:
  64.     pushem    <es,ds,di,si,dx,cx,ax,bx>    ; dont change ax, bx order
  65.     xor    ah, ah
  66.     shl    ax, 1                ; ax = function index
  67.     xchg    ax, bx
  68.     mov    bx, cs:DispatchTable[bx]    ; function ptr in bx
  69.     xchg    ax, bx
  70.     call    ax
  71. DirectReturn:
  72.     popem    <bx,ax,cx,dx,si,di,ds,es>    ; dont change ax, bx order
  73.     mov    ax, cs:Status
  74.     ret
  75. VESAFNotAValidFunction:
  76.     cmp    al, 70h
  77.     jne    @f
  78.     call    SetChipsWindowSize
  79.     mov    ax, 704fh
  80.     ret
  81. @@:
  82.     cmp    al, 71h
  83.     jne    @f
  84.     call    GetChipsWindowSize
  85.     mov    ax, 714fh
  86.     ret
  87. @@:
  88.     xor    al, al        ; function not supported
  89.     ret
  90. VESAFunctions endp
  91.  
  92.  
  93.  
  94. SuperVGAInfo    proc    near
  95. ;
  96. ; copy our info structure
  97. ;
  98.     cld                ; play it safe, don't assume things
  99.     mov    ax, cs
  100.     mov    ds, ax            ; Set our data segment
  101.     mov    si, OFFSET VGAInfo
  102.     mov    cx, (SIZE VGAInfoBlock) / 2
  103.     rep movsw
  104. IF    (SIZE VGAInfoBlock) AND 1
  105.     movsb
  106. ENDIF
  107. if 0    ;** we assume that 82C452 presence is already been checked, when we installed this TSR
  108. ;
  109. ; Look for 82C452 (CHIPS Super VGA)
  110. ;
  111.     call    ReadChipsVGAId        ; Id is returned in ah
  112. ;
  113. ; if VGA is identified as Chips product then look for specific VGA
  114. ; look for Chips Id
  115. ;
  116.     cmp    ah, CHIPS_ID    ; is it chips Id?
  117.     jnz    VGACError00    ; non Chips VGA/EGA
  118. ;
  119. ; VGA is identified as Chips VGA
  120. ;
  121.     mov    ah, 80H        ; open extended registers at 3d6/3d7H
  122.     call    ExtRegs
  123.     call    ReadVGATypeNRev
  124.     mov    bl, ah        ; place this info to proper reg
  125.     and    ah, 0F0H    ; test VGA type
  126.     cmp    ah, CHIPSVGA_452
  127.     jnz    VGACFNot452
  128. ;
  129. ; 82C452 is found, return success
  130. ;
  131. endif    ;**0
  132.     mov    Status, SUCCESS SHL 8 + VESA_FUNCTIONS
  133.     ret
  134. if 0    ;** Presence of 82c452 is alraedy been checked
  135. VGACError00:
  136. VGACFNot452:
  137.     mov    Status, FAILURE SHL 8 + VESA_FUNCTIONS
  138.     ret
  139. endif    ;** 0
  140. SuperVGAInfo    endp
  141.  
  142.  
  143.  
  144. SuperVGAModeInfo proc    near
  145.     cld                ; play it safe
  146.     mov    ax, cs
  147.     mov    ds, ax            ; Set our data segment
  148.     mov    si, OFFSET ModeInfo
  149.     mov    ax, cx            ; VESA Mode No ****** to be changed to bx
  150.     mov    dx, di            ; save di in dx
  151.     mov    bx, es            ; save es in bx
  152.     call    VESAToInternalMode
  153.     call    InternalModeToIndex
  154.     mov    ax, di            ; al = Mode Index
  155.     mov    ah, SIZE ModeInfoBlock
  156.     mul    ah            ; ax = +(SIZE ModeInfoBlock)*Index
  157.     add    si, ax            ; si = ModeInfo+(SIZE ModeInfoBlock)*Index
  158.     mov    di, dx            ; restore di
  159.     mov    es, bx            ; restore es
  160.     mov    cx, OBLG_INFO_SIZE
  161.     test    [si].ModeAttributes, MA_EXT_INFO
  162.     jz    @F
  163.     add    cx, EXT_INFO_SIZE
  164. @@:
  165.     push    di            ; save start address
  166.     rep movsb
  167.     pop    di            ; restore start adress
  168.     mov    ax, word ptr ChipsNoOfWindows
  169.                     ; al = # of Windows, ah = Window Size
  170.     cmp    al, 1            ; Is there only 1 windows supported
  171.     jz    @F            ; By default we enable only one window
  172.     mov    es:[di].WinBAttributes,WIN_ATTR    ; Enable second window also
  173.     cmp    ah, 64            ; Is it Dual page 64K ?
  174.     jz    @F            ; Yes, we are all set
  175.     mov    es:[di].WinBSegment, WINB_NADDR    ; change selector to dual page 32K windows
  176. @@:
  177.     mov    byte ptr es:[di].WinSize, ah    ; copy size of the window
  178.     mov    cs:Status, SUCCESS SHL 8 + VESA_FUNCTIONS
  179.     ret
  180. SuperVGAModeInfo endp
  181.  
  182.  
  183.  
  184. SuperVGASetMode    proc    near
  185.     mov    ax, bx                ; ax = VESA Mode
  186.     call    VESAToInternalMode        ; ax = Internal Mode (BIOS Mode)
  187.     mov    bx, ax                ; save internal mode
  188.     and    ah, ah                ; see if ah = 0
  189.     jnz    SVSMError
  190.     int    10H                ; call BIOS to set mode
  191. ; did BIOS set the mode ?
  192.     mov    ax, 40h
  193.     mov    ds, ax
  194.     mov    di, 49h
  195.     and    bl, NOT 80H            ; Clear Not-clear-memory bit
  196.     cmp    [di], bl
  197.     jnz    SVSMError
  198. ;
  199. ; find out what value is to be programmed in the GR06 and XR0B to select
  200. ; proper CPU address window. We have table of these value so we have
  201. ; to compute index to the table first. There are 4 entries in the table.
  202. ;    NumberOfWin    SizeofWin    XR0B    GR06 (Low)
  203. ;    1        64 K        0    4
  204. ;    1        128K        0    0
  205. ;    2        32 K        2    4
  206. ;    2        64 K        2    0
  207. ; We assume that # of windows and windows size will always have these values
  208. ;
  209.     cmp    bl, 6ah            ; For all standard modes and 132 column modes
  210.     jb    StandardModes        ; don't bother about paging etc
  211.     mov    bx, word ptr cs:ChipsNoOfWindows
  212.                     ; bl = # of Windows, bh = Window Size
  213.     mov    cl, 6            ; # of bits to be shifted
  214.     shr    bl, 1            ; 'C' if bl = 1, bl = 0/1
  215.     adc    cl, 0            ; cl = 6/5
  216.     shr    bh, cl            ; bl = 0/1
  217.     shl    bl, 1
  218.     add    bl, bh
  219.     xor    bh, bh            ; bx = index into the table
  220.     shl    bx, 1            ; each entry is one word
  221.  
  222.     mov    dx, 3ceh        ; dx = Graphics Controller addr
  223.     mov    al, 6
  224.     out    dx, al
  225.     inc    dx
  226.     in    al, dx
  227.     and    al, 11110011b        ; clear memory size bits
  228.     or    al, cs:WinRegTable[bx]    ; GR06 value
  229.     out    dx, al
  230.  
  231.     mov    ah, 80h            ; Open extended registers
  232.     call    ExtRegs
  233.  
  234.     mov    dx, EGA_BASE + EXTR_ADDR
  235.     mov    al, 0bh
  236.     out    dx, al
  237.     inc    dx
  238.     in    al, dx            ; read current value
  239.     and    al, 11111101b        ; clear dual page bit
  240.     or    al, cs:WinRegTable[bx+1] ; XR0B value
  241.     out    dx, al
  242. StandardModes:
  243.  
  244.     mov    cs:Status, SUCCESS SHL 8 + VESA_FUNCTIONS
  245.     ret
  246. SVSMError:
  247.     mov    cs:Status, FAILURE SHL 8 + VESA_FUNCTIONS
  248.     ret
  249. SuperVGASetMode    endp
  250.  
  251.  
  252.  
  253. SuperVGAGetMode    proc    near
  254.     mov    ax, 0F00H
  255.     int    10H
  256.     xor    ah, ah            
  257.     mov    bx, ax            ; save this info in bx
  258.     call    InternalModeToVesa
  259.     jnc    @F
  260.     xchg    ax, bx
  261. @@:
  262.     pop    dx            ; get return addr
  263.     pop    ax            ; pop bx in ax *******
  264.     push    bx            ; push mode to be returned
  265.     push    dx            ; 
  266.     mov    cs:Status, SUCCESS SHL 8 + VESA_FUNCTIONS
  267.     ret
  268. SuperVGAGetMode    endp
  269.  
  270.  
  271.  
  272. SuperVGAVideoState    proc    near
  273.     mov    ah, 1cH                ; ah = BIOS function to save/restore VIDEO state
  274.     mov    al, dl                ; al = subfunction
  275.     push    ax                ; save function
  276.     push    cx
  277.     test    cx, VS_SUPERVGA_STATE
  278.     jz    SVVSNotSuperVGA0
  279. ;
  280. ; Super VGA state
  281. ;
  282.     cmp    al, VS_GET_BUFSIZE
  283.     jnz    SVVSNotBufSize
  284. ;
  285. ; get buf size function
  286. ;
  287.     cmp    cx, VS_SUPERVGA_STATE        ; if it is SUPERVGA_STATE only
  288.     jnz    @F                ; save cx, ax and call BIOS
  289. ; only SUPERVGA_STATE
  290.     mov    bx, SUPERVGA_SIZE
  291.     pop    cx
  292.     pop    ax                ; restore sunfunction
  293.     jmp    SVVSNotSuperVGA1        ; don't call BIOS
  294.  
  295. SVVSNotBufSize:
  296.     cmp    al, VS_SAVE_STATE
  297.     jnz    SVVSNotSaveState
  298. ;
  299. ; save state function
  300. ; es:bx --> pointer to buffer, bx will be updated by routine
  301. ;
  302.     call    SaveSuperVGAState
  303.     jmp    short @F
  304. SVVSNotSaveState:
  305.     cmp    al, VS_RESTORE_STATE
  306.     jnz    SVVSNotRestoreState
  307. ;
  308. ; restore state function
  309. ; es:bx --> pointer to buffer, bx will be updated by routine
  310. ;
  311.     call    RestoreSuperVGAState
  312. SVVSNotRestoreState:
  313. SVVSNotSuperVGA0:
  314. @@:
  315.     int    10H
  316.     pop    cx                ; restore requested state
  317.     pop    ax                ; restore subfunction function
  318.     test    cx, VS_SUPERVGA_STATE
  319.     jz    SVVSNotSuperVGA1
  320. ; super vga function
  321.     cmp    al, VS_GET_BUFSIZE        ; is it GET_BUFSIZE function ?
  322.     jnz    @F                ; no
  323.     add    bx, SUPERVGA_SIZE        ; add # of full block
  324. SVVSNotSuperVGA1:
  325.     pop    dx                ; pop return address
  326.     pop    ax                ; pop bx in ax *******
  327.     push    bx                ; put bx on stack
  328.     push    dx                ; push new address
  329. @@:
  330.     mov    cs:Status, SUCCESS SHL 8